package gui.jquery.chrono.views;
import gui.jquery.chrono.managers.SliderManager;

import java.util.ArrayList;
import java.util.Hashtable;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JSlider;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * 
 * @author MAMATU
 *
 */
@SuppressWarnings("serial")
public class ChronoSliderPanel extends JPanel implements MouseListener {
	
	private java.util.Hashtable<Integer, JLabel> labelsDim;
	private java.util.Hashtable<Integer, JLabel> labelsValue;
	private JSlider sl_dim ;
	private JSlider sl_values;
	
	private SliderManager manager;
	
	/**
	 * GET&SET
	 */
	public SliderManager getManager() {return manager;}
	public JSlider getSliderDIM() {return sl_dim;}
	public Hashtable<Integer, JLabel> getLabelsDIM() {return labelsDim;}
	public JSlider getSliderVAL() {return sl_values;}
	public Hashtable<Integer, JLabel> getLabelsVAL() {return labelsValue;}

	/**
	 * Create the panel.
	 */
	public ChronoSliderPanel() {
		setBorder(new TitledBorder(null, "Chronological Slider", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setLayout(null);
		
		labelsDim = new java.util.Hashtable<Integer, JLabel> ();
		labelsValue = new java.util.Hashtable<Integer, JLabel> ();
		
		manager = new SliderManager(this);
		
		sl_dim = new JSlider();
		sl_dim.addMouseListener(this);
		sl_dim.setBounds(25, 31, 867, 48);
		add(sl_dim);
		
		sl_values = new JSlider();
		sl_values.addMouseListener(this);
		sl_values.setBounds(25, 81, 867, 48);
		add(sl_values);
		
		manager.updateDIM();
		manager.updateValues();

	}
	
	

	

	
	
	
	
	
	
	/**
	 * Permet de remplire le slider dimension avec une liste de string.
	 * 
	 * @param params liste de string
	 */
	public void setDIMSliderParameter(ArrayList<String> params){
		// On efface tout
		labelsDim.clear();
		
		// On remplie
		int i = 0;
		
		for (String s : params){
			labelsDim.put(i,new JLabel(s));
			i++;
			
		}
		if (labelsDim.isEmpty()) labelsDim.put(0,new JLabel(""));
		sl_dim.setMaximum(labelsDim.size()-1);
		sl_dim.setLabelTable(labelsDim);
		sl_dim.setPaintTicks(true);
		sl_dim.setPaintLabels(true);
		
		
		// On update
		
	
		sl_dim.updateUI();

	}
	
	
	
	
	/**
	 * Permet de remplire le slider valeurs avec une liste de string.
	 * 
	 * @param params liste de string
	 */
	public void setValueSliderParameter(ArrayList<String> params){
		// On efface tout
		labelsValue.clear();
		
		// On remplie
		int i = 0;
		
		for (String s : params){
			labelsValue.put(i,new JLabel(s));
			i++;
			
		}
		
		if (labelsValue.isEmpty()) labelsValue.put(0,new JLabel(""));
		sl_values.setMaximum(labelsValue.size()-1);
		sl_values.setLabelTable(labelsValue);
		sl_values.setPaintTicks(true);
		sl_values.setPaintLabels(true);
		
		
		// On update
	
		sl_values.updateUI();

	}
	
	
	
	

	/**
	 * Events
	 */
	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
	}
		
	@Override
    public void mouseReleased(MouseEvent e) {

    	// Si on relache la souris sur le slider des valeurs 
    	if (e.getSource() == sl_values) {
    	
    		this.updateUI();
    		manager.getGlobalManager().updateRequest();
    	}
    	
    	// Si on relache la souris sur le slider des dimentions 
    	if (e.getSource() == sl_dim) {
    		
    		manager.updateValues();
    		manager.getGlobalManager().updateRequest();
    		
    	}
    } 

}
